﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameLib.Serialization
{
	public abstract class Serializer
	{
		public abstract bool Deserialize(object obj, string dataPath);
		public abstract bool Serialize(object obj, string dataPath);

		public abstract Type SupportedType { get; }

	/*
		public virtual bool SupportInterface
		{
			get { return false; }
		}*/

		public virtual bool Support(Type type)
		{
			if (SupportedType != null)
				return SupportedType.IsAssignableFrom(type);
			return false;
		}

		public abstract DataType DataType { get; }
	

		public DataHandler DataHandler
		{
			get;
			set;
		}
	}

	public abstract class Serializer<T> : Serializer where T:class
	{
		public override Type SupportedType
		{
			get { return typeof(T); }
		}

		public override bool Deserialize(object obj, string dataPath)
		{
			T objTyped = obj as T;

			if (objTyped == null)
				throw new ArgumentNullException();

			return Deserialize(objTyped, dataPath);
		}

		public override bool Serialize(object obj, string dataPath)
		{
			T objTyped = obj as T;

			if (objTyped == null)
				throw new ArgumentNullException();

			return Serialize(objTyped, dataPath);
		}

		public abstract bool Deserialize(T obj, string dataPath);
		public abstract bool Serialize(T obj, string dataPath);


	}
}
